Loop through enum C#

42

Loop through enum C# -

enum Foos {
  Foo,
  Bar,
}

foreach(Foos val in Enum.GetValues(typeof(Foos))) {
  //Do whatever with the value :D
}

loop through all enum values in C# -

var values = Enum.GetValues(typeof(Foos));
foreach(Foos foo in values) {
	// do something, use foo
}

// or
foreach(Foos foo in Enum.GetValues(typeof(Foos))) {
	// do something, use foo
}

traversing an enum c# -

var values = Enum.GetValues(typeof(Foos)).Cast<Foos>();

c# iterate enum -

var values = Enum.GetValues(typeof(Foos));

c# iterate enum -

var values = Enum.GetValues(typeof(Foos));

Comments

Submit
0 Comments